<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CateController extends Controller
{
    /**
     * 分类列表
     */
    public function getIndex(Request $request){
        //每页显示条数
        $num = $request->input('num',15);

        //检测是否提交查询关键字
        if($request->has('keywords')){
            //分页查询 select * from user where username like '%admin%';
            $cates = DB::table('cate')->where('title','like','%'.$request->input('keywords').'%')->paginate($num);
        }else{
            $cates = DB::table('cate')->paginate($num);
        }

        //提取参数 分配到页面中
        $data = $request->except('page');

        //解析模板 分配数据
        return view('Admin.cate.index',['cates'=>$cates,'data'=>$data]);
    }

    /**
     * 分类添加
     */
    public function getAdd(){
        //查询已有的分类
        $cates = DB::table('cate')->get();

        return view('Admin.cate.add',['cates'=>$cates]);
    }
}
